home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Windows 95 Programs / Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso / 1132 / nnunit.txt < prev    next >
Text File  |  1997-04-16  |  24KB  |  674 lines

  1. Neuralnet Tools 
  2.  
  3. NEURAL NETWORKS TOOLKIT
  4.  
  5. Version 1.0
  6.  
  7. COPYRIGHT  SOUTHERN SCIENTIFIC cc
  8. 17 CAPRI RD
  9. ST JAMES
  10. SOUTH AFRICA
  11. December 1992
  12.  
  13.  
  14. This Turbo Pascal unit was constructed with TP 6.0.  It includes
  15. the basic tools necessary for the implementation of neural nets
  16. - to date, objects include neurons and nets of neurons.  The
  17. unit uses the dynamic matrix unit, DYNA2, supplied with this
  18. unit.  In order to make full use of this unit, you should
  19. understand the Tcollection object supplied with Turbo Pascal.
  20.  
  21. THE INTERFACE SECTION
  22.  
  23.  
  24. CONST
  25.      smallnumber        = 1.0e-9;
  26.      neuralerrmsgcount  = 11;
  27.      NeuralErrMsg  : array[1..neuralerrmsgcount] of string[80]
  28.             {1}    =('<<- Index zero or negative in addneuron >>>',
  29.             {2}      '<<- Index out of range in getneuron >>>',
  30.                      '<<- Neuron not in net in deleteneuron >>>',
  31.             {4}      '<<- Index out of range in addfield >>>',
  32.                      '<<- Field not in fieldlist in deletefield >>>',
  33.             {6}      '<<- Field not in fieldlist in killfield >>>',
  34.                      '<<- Neuron has no inputs above threshold >>>',
  35.             {8}      '<<- Datalength doesn''t match neuronfield >>>',
  36.                      '<<- Field not in fieldlist in connect >>>',
  37.            {10}      '<<- Field not in fieldlist in connectbetween >>>',
  38.                      '<<- Field not in fieldlist in setfieldsignal >>>'
  39.                     );
  40.  
  41.  
  42. VAR
  43.    NeuralError   : integer;  {flags error conditions }
  44.  
  45. TYPE
  46.      pnum           = ^double;
  47.      pNeuronstate   = ^Neuronstate;
  48.  
  49.      Neuronstate    = record
  50.         activation  : double;
  51.         output      : double;
  52.      end;
  53.  
  54.      Neuronfield    = pcollection;  { of neurons }
  55.      psignalfunc    = ^signalfunc;
  56.      signalfunc     = function(a : double): double;
  57.      funcname       = string[20];
  58.  
  59.                     {Signalfunctions}
  60.      signaltype     = (linear,
  61.                        arctangent,
  62.                        tanh,
  63.                        halfsine,
  64.                        step,
  65.                        sigmoid,
  66.                        gaussian,
  67.                        one,
  68.                        zero);
  69.                     {Derivatives of signalfunctions}
  70.      dsignaltype    = (darctangent,
  71.                        dtanh,
  72.                        dhalfsine,
  73.                        dsigmoid,
  74.                        dgaussian
  75.                       );
  76.  
  77. CONST
  78.      reststate      : neuronstate = (activation:0;output:0);
  79.      signalnames    : array[signaltype] of funcname =
  80.                             ('linear',
  81.                              'arctangent',
  82.                              'tanh',
  83.                              'halfsine'  ,
  84.                              'step',
  85.                              'sigmoid'   ,
  86.                              'gaussian'  ,
  87.                              'one',
  88.                              'zero' );
  89.  
  90.     dsignalnames   : array[dsignaltype] of funcname =
  91.                             ('darctangent',
  92.                              'dtanh',
  93.                              'dhalfsine'  ,
  94.                              'dsigmoid'   ,
  95.                              'dgaussian'
  96.                             );
  97.  
  98. TYPE
  99.  
  100.      Pneuron= ^Neuron;
  101. {=-----------------------------------}
  102.      Neuron = OBJECT(Tobject)
  103. {=-----------------------------------}
  104.  
  105.         sfunctype  : signaltype;
  106.         sfunc      : signalfunc;  { transfer function}
  107.         dsfunc     : signalfunc;  { derivative of transfer function}
  108.         scalar     : double;      { scalar for activation}
  109.         state      : Neuronstate; { unfired; for timing purposes}
  110.         output     : double;      { value at output after firing}
  111.         error      : double;      { current error}
  112.         lasterror  : double;      { previous error}
  113.         constructor init(xfer   : signaltype;
  114.                          initial: Neuronstate);
  115.         constructor load(var s: tstream);
  116.         procedure   store(var s: tstream);
  117.         procedure   setsignal(xfer : signaltype);
  118.         procedure   setscale (s    : double);
  119.         procedure   getstate(var s: Neuronstate);
  120.         procedure   calcstate(sigma    : double); {sigma = inner prod of
  121.                                                  weights and
  122.                                                  network inputs}
  123.         procedure   fire;             {make output available}
  124.         destructor  done; virtual;
  125.      end;
  126.  
  127. const
  128.  
  129.      Rneuron : tstreamrec = (
  130.              objtype      : 11400;
  131.              vmtlink      : ofs(typeof(neuron)^);
  132.              load         : @neuron.load;
  133.              store        : @neuron.store
  134.      );
  135.  
  136.  
  137. type
  138.      pneuralnet  = ^neuralnet;
  139. {-------------------------------------}
  140.      Neuralnet   = OBJECT(tcollection)   { of Neuron's }
  141. {-------------------------------------}
  142.  
  143.      Weights     : pdynamat;
  144.      fieldlist   : pcollection;  {each entry points to a
  145.                                   collection of neurons -
  146.                                  }
  147.      inputfield : neuronfield; { pointer to input collection }
  148.      outputfield: neuronfield; { pointer to output collection }
  149.  
  150.      constructor init(total: integer);
  151.      constructor load(var s: tstream);
  152.      procedure   store(var s: tstream);
  153.      procedure   addneuron(i : integer; var aneuron : pneuron); virtual;
  154.      procedure   getneuron(i : integer; var aneuron : pneuron); virtual;
  155.      procedure   calcallstates; virtual;
  156.      procedure   deleteneuron(var aneuron : pneuron);virtual;
  157.      procedure   addfield(var field      : neuronfield;
  158.                            startat, endat : integer);     virtual;
  159.      procedure   deletefield(var field : neuronfield); virtual;
  160.      procedure   fireall; virtual;
  161.      procedure   killfield(var field   : neuronfield); virtual;
  162.      procedure   getinputsof(thisone   : pneuron;
  163.                              threshold : double;
  164.                              var field : neuronfield);    virtual;
  165.      procedure   presentinputto(thefield  : neuronfield;
  166.                                 thedata   : pdynavec);    virtual;
  167.      procedure   connect(var f:neuronfield; weight: double);virtual;
  168.      procedure   disconnect(var f:neuronfield);virtual;
  169.      procedure   connectbetween(var from,into: neuronfield;
  170.                                     weight: double); virtual;
  171.      procedure   disconnectbetween(var from,into: neuronfield); virtual;
  172.      procedure   propagate; virtual;
  173.      procedure   randomweights(alimit : double); virtual;
  174.      procedure   nofeedback; virtual;
  175.      procedure   setfieldsignal(var field : neuronfield;s :
  176.                   signaltype); virtual; destructor  done; virtual; end;
  177.  
  178. const
  179.  
  180.      Rneuralnet : tstreamrec = (
  181.              objtype      : 11401;
  182.              vmtlink      : ofs(typeof(neuralnet)^);
  183.              load         : @neuralnet.load;
  184.              store        : @neuralnet.store
  185.      );
  186.  
  187.  
  188.  
  189.                                         {prefix 'f' => signal function
  190.                                          prefix 'fd' => derivative
  191.                                         }
  192. function flinear(a: double): double;
  193. function farctan(a:double): double;
  194. function fdarctan(a:double): double;
  195. function ftanh(a: double): double;
  196. function fdtanh(tanhx: double) : double;
  197. function fhalfsine(a: double): double;
  198. function fdhalfsine(a: double): double;
  199. function fstep(a: double): double;
  200. function fsigmoid(a: double): double;
  201. function fdsigmoid(sigx: double): double;
  202. function fgaussian(a: double): double;
  203. function fdgaussian(a: double): double;
  204. function fone(a : double)     : double;   {always one. For offset neurons}
  205. function fzero(a: double): double;
  206.  
  207. function findsignalfunc(deriv: boolean; ftype : signaltype): pointer;
  208.  
  209. procedure printneuralerror;         { Prints the current error                             message or nothing if all is well}
  210.  
  211.  
  212.  
  213. THE NEURON OBJECT
  214.  
  215.  
  216. NEURON FIELDS
  217.  
  218.     Sfunctype : Signaltype Contains the signal funtion type
  219. used by the neuron.  Signaltype is an enumerated type with
  220. possible values listed above.
  221.  
  222.     Sfunc : Signalfunc A procedural variable denoting the
  223. signalfunction to call.  Sfunc takes one parameter of type
  224. double (the activation of the neuron) and returns a double.
  225.  
  226.     dSfunc : Signalfunc A procedural variable denoting the
  227. function which returns the derivative of Sfunc.  dSfunc takes
  228. one parameter of type double (the activation of the neuron) and
  229. returns a double.
  230.  
  231.     <<<<<< A note about setting up signalfunctions: >>>>>>
  232.  
  233. When the neuron object is initialized, the addresses of the
  234. signalfunctions are resolved (see the 'Neuron Fields' section,
  235. where the code is given).  As it stands, this unit makes an
  236. exeption  for 2 cases where the derivative of the function is a
  237. simple function of the function value itself : here, the
  238. parameter passed to the derivative is the function value, not
  239. the activation.  Watch out  for this when you write gradient
  240. based training regimes.  I did this because it speeds up
  241. training - the function value is already available by the time
  242. the derivative needs to be calculated. The transfer funtions in
  243. question are the SIGMOID function and the HYPERBOLIC TANGENT
  244. function.   You can also do this for the GAUSSIAN function, but
  245. I didn't.  I know this is a little messy, but you can easily
  246. change it if you want.  Here's the code :
  247.  
  248. {--------------------------------} 
  249. function farctan(a: double):double; 
  250. {--------------------------------} 
  251. begin 
  252. farctan :=2.0/pi*arctan(a);       { ...limits are -1 and 1 } end;
  253.  
  254. {--------------------------------}
  255. function fdarctan(a: double): double;
  256. {--------------------------------}
  257. begin
  258.       fdarctan := 1.0/(1.0+a*a)
  259. end;
  260.  
  261. {--------------------------------}
  262. function ftanh(a: double): double;
  263. {--------------------------------}
  264.  
  265.  
  266. var
  267.    e,inv  : double;
  268. begin
  269.      e    := exp(a);
  270.      inv  := 1.0/e;
  271.      ftanh:= (e-inv)/(e+inv);
  272. end;
  273.  
  274. {--------------------------------}
  275. function fdtanh(tanhx: double): double;
  276. {--------------------------------}
  277. begin
  278.      fdtanh := (1.0-tanhx*tanhx);
  279. end;
  280.  
  281.  
  282. {--------------------------------}
  283. function fsigmoid(a: double): double;
  284. {--------------------------------}
  285. begin
  286.      fsigmoid := 1.0/(1.0 + exp(-a));
  287. end;
  288.  
  289. {--------------------------------}
  290. function fdsigmoid(sigx: double): double;  {a is fsigmoid(x) }
  291. {--------------------------------}
  292. begin
  293.      fdsigmoid := sigx*(1-sigx);
  294. end;
  295.  
  296. {--------------------------------}
  297. function fgaussian(a: double): double;
  298. {--------------------------------}
  299. begin
  300.      fgaussian := exp(-a*a);
  301. end;
  302.  
  303. {--------------------------------}
  304. function fdgaussian(a: double): double;
  305. {--------------------------------}
  306. begin
  307.      fdgaussian:= -2.0*a*fgaussian(a);
  308. end;
  309.  
  310. {--------------------------------}
  311. function flinear(a:double): double;
  312. {--------------------------------}
  313. begin
  314.           flinear := a;
  315. end;
  316.  
  317. {--------------------------------}
  318. function fhalfsine(a: double): double;
  319. {--------------------------------}
  320. begin
  321.      if (a > pi/2.0)
  322.        then fhalfsine := 1.0
  323.      else
  324.        if (a < -pi/2.0)
  325.           then fhalfsine := -1.0
  326.        else
  327.           fhalfsine := sin(a);
  328.  
  329. end;
  330.  
  331. {--------------------------------}
  332. function fdhalfsine(a: double): double; {Cheat with derivative}
  333. {--------------------------------}
  334. begin
  335.      if (a > pi/2.0)
  336.        then fdhalfsine := 1.0
  337.      else
  338.        if (a < -pi/2.0)
  339.           then fdhalfsine := -1.0
  340.        else
  341.           fdhalfsine := cos(a);
  342.  
  343. end;
  344.  
  345. {--------------------------------}
  346. function fstep(a: double): double;
  347. {--------------------------------}
  348. begin
  349.      if a<0 then fstep := -1 else fstep := 1;
  350. end;
  351.  
  352. {--------------------------------}
  353. function fone(a: double): double;
  354. {--------------------------------}
  355. begin
  356.      fone := 1.0;
  357. end;
  358.  
  359. {--------------------------------}
  360. function fzero(a: double): double;
  361. {--------------------------------}
  362. begin
  363.      fzero := 0.0;
  364. end;
  365.  
  366. {--------------------------------}
  367. function findsignalfunc(deriv : boolean; ftype : signaltype): pointer;
  368. {--------------------------------}
  369.  
  370.                           {If deriv is true, returns pointer
  371.                            to the derivative function
  372.                            of ftype
  373.                            NB - See p 55 of programmers guide TPW
  374.                           }
  375. begin
  376.    if not deriv then
  377.      case ftype of
  378.        linear    : findsignalfunc := (@flinear);
  379.        arctangent: findsignalfunc := (@farctan);
  380.        tanh      : findsignalfunc := (@ftanh);
  381.        halfsine  : findsignalfunc := (@fhalfsine);
  382.        step      : findsignalfunc := (@fstep);
  383.        sigmoid   : findsignalfunc := (@fsigmoid);
  384.        gaussian  : findsignalfunc := (@fgaussian);
  385.        one       : findsignalfunc := (@fone);
  386.        zero      : findsignalfunc := (@fzero);
  387.      end
  388.    else
  389.      case ftype of
  390.        linear    : findsignalfunc := (@fone);
  391.        arctangent: findsignalfunc := (@fdarctan);
  392.        tanh      : findsignalfunc := (@fdtanh);
  393.        halfsine  : findsignalfunc := (@fdhalfsine);
  394.        step      : findsignalfunc := (@fzero);
  395.        sigmoid   : findsignalfunc := (@fdsigmoid);
  396.        gaussian  : findsignalfunc := (@fdgaussian);
  397.        one       : findsignalfunc := (@fzero);
  398.        zero      : findsignalfunc := (@fzero);
  399.      end;
  400. end;
  401.  
  402.  
  403. (No attempt was made to optimize the buggers, and my first
  404. implementation of lookup tables failed to beat the 80387 - maybe
  405. you can help.)
  406.  
  407.     Scalar : double
  408.     Contains a scalar for scaling of the activation before
  409. transformation by sfunc.
  410.  
  411.     State : neuronstate
  412.  
  413.     A record holding the current state (activation and
  414. output ) of the neuron. State.output is the value that appears
  415. at neuron.output after fire is called.  This variable is a
  416. 'buffer' for the neuronstate, so that it may remain hidden from
  417. the network until the algorithm requires a new output, and the
  418. neuron formally fires.
  419.  
  420.     Output : double
  421.     The output from the neuron available to the network for
  422. interaction with other neurons.
  423.  
  424. Error, Lasterror : double
  425. Current and previous error.  Used for some training algorithms.
  426.  
  427.  
  428. NEURON METHODS
  429.  
  430.  constructor init(xfer   : signaltype; initial: neuronstate);
  431.     The neuron is initialized by specifying a signalfunction
  432. type and an initial neuronstate (see the constant 'reststate').
  433. Calls setsignal, and sets scalar to 1.0.
  434.  
  435.  
  436. procedure neuron.store(var s: tstream);
  437.  
  438.     Writes the neuron to the stream s as follows :
  439. sfunctype, scalar, state, output, error, lasterror.
  440.  
  441.  
  442. constructor neuron.load(var s: tstream);
  443.  
  444.     Reads the neuron from the stream s by reading sfunctype,
  445. scalar, state, output, error, lasterror in this order, and then
  446. calling setsignal(sfunctype).
  447.  
  448.  
  449. procedure setsignal(xfer : signaltype); Sets sfunctype to xfer
  450. and calls findsignalfunc to establish the address of the
  451. signalfunction. Sets Sfunc and dSfunc to the correct functions.
  452. After this call, the neuron uses Sfunc to calculate its output.
  453. The user may use dSfunc as necessary, e.g. in a training
  454. algorithm.  Setsignal looks like this :
  455.  
  456. {--------------------------------}
  457. procedure neuron.setsignal(xfer : signaltype);
  458. {--------------------------------}
  459.  
  460.                { Changes the neuron's signal function.
  461.                }
  462. begin
  463.      sfunctype  := xfer;
  464.      @sfunc     := findsignalfunc(false,xfer);
  465.      @dsfunc   := findsignalfunc(true,xfer);
  466. end;
  467.  
  468. procedure setscale (s    : double);
  469.     Simply sets scalar to s.
  470.     
  471. procedure getstate(var s: Neuronstate);
  472.     Returns the current state of the neuron in s.
  473.  
  474. procedure calcstate(sigma    : double); 
  475. Sigma = inner prod of
  476. weights and inputs to this neuron.  Sets activation to sigma and
  477. calls the signalfunction set by setsignal with parameter
  478. scalar*sigma.
  479.     
  480. procedure fire;       
  481.     Sets neuron.output to the current  value in
  482. state.output, thereby making the output of the neuron available
  483. to the outside world.
  484.  
  485. Destructor Done; 
  486. Nothing special here.  Calls the ancestors done
  487. method.  
  488. 
  489.  
  490. THE NEURALNET OBJECT
  491.  
  492.  
  493. NEURALNET FIELDS
  494.  
  495. Weights     : pdynamat;
  496.     Pointer to the weights matrix.  See the unit DYNA2.
  497.  
  498. fieldlist   : pcollection;  
  499.     Fieldlist points at a collection of neuronfields(each
  500. neuronfield is a pointer to a collection of neurons).  These
  501. fields represent collections of neurons that the user considers
  502. to be a logical unit, such as an input field, hidden field and
  503. output field.  Neuralnet methods can access and manipulate
  504. fields in this list.  Once fields are inserted into fieldlist,
  505. the neuralnet object assumes responsibility for their
  506. manipulation and disposal.  It is wise to use only methods of
  507. the neuralnet object to manipulate a field of neurons after it
  508. becomes the property of the network.  Note that it it may
  509. sometimes be useful to insert the whole network into fieldlist.
  510.  
  511. inputfield    : neuronfield;
  512. outputfield    : neuronfield;
  513.     Pointers to output and input fields.  These are NIL
  514. after the init method is called, and are provided for
  515. convenience, since most nets have them.  You need not use them.
  516.  
  517. NEURALNET METHODS
  518.  
  519. Constructor init(total: integer);
  520.     The number of neurons specified in total are created on
  521. the heap with  the linear signal function and in the reststate.
  522. The neurons are inserted into the collection.  The weights
  523. matrix  is created on the heap with dimensions (total,total) and
  524. each entry is set to 0.01  The fieldlist is created on the heap
  525. ( init(3,1) ) and inputfield and outputfield are set to NIL.
  526.  
  527. Constructor load(var s : tstream);
  528.  
  529.     Loads the net from the stream s.
  530.  
  531. Procedure store(var s : tstream);
  532.  
  533.     Stores the net on the stream s.
  534.  
  535. procedure   addneuron(i : integer; var aneuron : pneuron); virtual;
  536.     Makes a new neuron, adds it at position i in the net and
  537. adjusts the weights matrix.  On exit, aneuron points to the new,
  538. completely disconnected neuron, the i'th in the net
  539. (indexof(aneuron) = i-1).  Disposing of the new neuron is the
  540. net's responsibility.  Aneuron is set to NIL on entry, and is
  541. NIL on failure.    If i doesn't make sense, an error is posted
  542. in neuralerror.  The new neuron doesn't belong to any of the
  543. fields in fieldlist.
  544.  
  545. procedure   getneuron(i : integer; var aneuron : pneuron); virtual;
  546.     Returns with aneuron pointing to neuron # i in the net,
  547. i.e neuron with index i-1.  Aneuron should be NIL on entry and
  548. is NIL if i doesn't make sense.
  549.  
  550. procedure   deleteneuron(var aneuron : pneuron);virtual;
  551.     Deletes and disposes the neuron from the net and deletes
  552. it from any fields in fieldlist.  Fixes weights matrix.  If the
  553. neuron is not in the net, nothing is done and an error is posted
  554. in neuralerror.
  555.  
  556.  
  557. procedure   addfield(var field      : neuronfield; startat, endat : integer);virtual;
  558.     On entry, field points to nothing.  A field is
  559. initialized, neurons are inserted and the field inserted into
  560. the fieldlist.  The new field contains neurons from # startat to
  561. # endat (counting from 1) inclusive, in the network. No neurons
  562. are created.  Disposing the field becomes the responsibility of
  563. the network.  If startat or endat do not index neurons in the
  564. network, or startat > endat, nothing is done and an error is
  565. posted in neuralerror.
  566.  
  567.  
  568. procedure   deletefield(var field : neuronfield); virtual;
  569.     Removes a field from the fieldlist. The items in field
  570. are deleted from field (not disposed) and the field is disposed.
  571. Field is NIL on exit if successfull.   If field is not in
  572. fieldlist,  nothing is done, and an error is posted in
  573. neuralerror.
  574.  
  575. procedure   killfield(var field   : neuronfield); virtual;
  576.     Removes field from fieldlist and deletes and disposes
  577. neurons in field from the net by calling deleteneuron (i.e.
  578. weights matrix is corrected, and errors reported).  Deletes all
  579. items in field.  Disposes field and returns nil in field if
  580. sucessfull.  If field is not in fieldlist, nothing is done and
  581. an error is posted in neuralerror.
  582.  
  583. procedure   getinputsof(thisone   : pneuron; threshold : double; var field : neuronfield);    virtual;
  584.     Finds neurons with absolute value of
  585. connections(weights) to thisone greater than threshold.  Assumes
  586. field is nil on entry.  Makes a new field, returns all neurons
  587. that meet this criterion in field.  Field is inserted into
  588. fieldlist.  Interprets 2nd index of weights matrix as
  589. destination - weights(i,j) means from neuron i into neuron j.
  590. If no neurons meet the criterion, nothing is done, field is NIL
  591. on exit and an error is posted in neuralerror.
  592.  
  593. procedure   presentinputto(thefield  : neuronfield; thedata   : pdynavec);    virtual;
  594.     Presents numeric data in thedata to thefield, and
  595. calculates the new state of each neuron in thefield.  Does not
  596. fire the neurons.  If the number of items in thefield is not the
  597. same as the number of items in thedata, nothing is done and an
  598. error is posted in neuralerror.  See also neuralnet.propagate.
  599.  
  600. procedure   connect(var f:neuronfield; weight: double);virtual;
  601.     Fully connects a field of neurons by setting the
  602. relevant entries in the weights matrix to weight.  If f is not
  603. in fieldlist, does nothing and posts an error in neuralerror.
  604.  
  605. procedure   disconnect(var f:neuronfield);virtual;
  606.     Fully disconnects a field of neurons.  Simply calls
  607. connect with a weight parameter of 0.0.
  608.  
  609. procedure   connectbetween(var from,into: neuronfield; weight: double); virtual;
  610.     Completely connects two neuronfields in one direction
  611. only by placing weight in the relevant positions of the weights
  612. matrix.  Thus, every neuron in the from field now propagates
  613. data to all neurons in the to field.  Does not remove existing
  614. connections in the other direction.  If either neuronfield is
  615. not in fieldlist, does nothing and posts an error in
  616. neuralerror.
  617.  
  618. procedure   disconnectbetween(var from,into: neuronfield); virtual;
  619.     Calls connectbetween with a weight parameter of 0.0;
  620.  
  621. procedure   propagate; virtual;
  622.     Fires all neurons, then calculates all new states.
  623. Simply calls fireall and calcallstates.
  624.  
  625. procedure   randomweights(alimit : double); virtual;
  626.     Randomizes all entries in the weights matrix to a random
  627. value between -limit...+limit with resolution 1/1000 of this
  628. interval.
  629.  
  630. procedure   nofeedback; virtual;
  631.     Sets all entries on the diagonal of the weights matrix
  632. to 0.0, thus preventing all neurons from feeding directly back
  633. into themselves.
  634.  
  635. procedure   setfieldsignal(var field : neuronfield; s     : signaltype); virtual;
  636.     Sets the signalfunction for all neurons in field to s.
  637. If field is not in fieldlist, does nothing and posts an error in
  638. neuralerror;
  639.  
  640. procedure fireall ; virtual;
  641.     Fires all neurons in the net by calling neuron.fire for
  642. each one.
  643.  
  644. procedure calcallstates; virtual;
  645.     Calculates the new state of each neuron. Calculates
  646. dotproducts of outputs and connected weights for each neuron -
  647. i.e. for neuron j, calculate  Sum(over i) of
  648. [output(i)*weights(i,j)] and calculate a new activation for
  649. neuron j.  (The problem of sparseness remains largely unsolved -
  650. perhaps it is more properly addressed in a new 'backpropnet'
  651. object which definitely has a sparse weights matrix...)
  652.  
  653. destructor  done; virtual;
  654.     Disposes the weights matrix.  Empties fieldlist and all
  655. fields in fieldlist and disposes these.  Calls Tcollection.done
  656. .
  657.  
  658.  
  659.  
  660.  {-------------------------- UNIT INITIALIZATION -----------------------}
  661.  
  662. begin
  663.      neuralerror := 0;
  664.      randomize;
  665.  
  666.         {Stream registration}
  667.  
  668.      registertype(Rneuron);
  669.      registertype(Rneuralnet);
  670.  
  671. end.
  672.  
  673.  
  674.